home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagd_f.zip / DRIVES.SWG / 0009_DRIVES4.PAS.pas < prev    next >
Pascal/Delphi Source File  |  1993-05-28  |  4KB  |  112 lines

  1. {
  2. > Does anyone know if there is a way For a Pascal Program to determine
  3. > whether a drive is a local hard drive, a network drive, a Dos
  4. > SUBSTituted drive, or a RAMDRIVE?
  5.  
  6. Hmm... I'm reading this one week after it got posted. and a month after the
  7. original question. I haven't read last week's messages, hope you hadn't
  8. recieved to many answers about this now. But because you apparently hadn't got
  9. anything two weeks after asking, I thought you may want this, so here comes...
  10.  
  11. There is a service in Dos that identifies a given drive as local or remote.
  12. This service also tells you if the drive is SUBSTed. You can also get info
  13. about whether it Uses removable media from another service. There is no way to
  14. detect a RAM-drive, as Far as I know, and I've got the facts from Microsoft's
  15. own MSJ! The Dos 5 DosSHELL simple checks the volume identifier. if it's
  16. 'MS-RAMDRIVE', 'RDV' or 'VDISK', the drive is ASSUMED to be a RAM-disk. But
  17. it's, again according to Microsoft Systems Journal, impossible to foolproof
  18. check if a drive is a logical RAM-drive. A design flaw in Dos.
  19.  
  20. However, I will show a few lines of TP-code For checking if a drive is remote
  21. or local, and SUBSTed or not. I use the TP 5.5 (and older) method of Intr-calls
  22. For simulating Asm, of course if could be written clearer With TP6's
  23. Asm-keyWord. The code consists of the actual Function and a test stub, cut the
  24. stub when you have looked at it. Code Compiles and runs fine on my system; I
  25. couldn't test if it work With remote drives, but it should. I've used similar
  26. code that worked With that too, so...
  27.  
  28. }
  29. Program TestDrv;
  30.  
  31. { --- A very short test-Program For Dos-IOCTL, Jacob Stedman 930223 --- }
  32.  
  33. Uses
  34.   Dos;
  35.  
  36. Function IsDriveValid(cDrive: Char; Var bLocal, bSUBST: Boolean): Boolean;
  37. {
  38.   Parameters: cDrive is the drive letter, 'A' to 'Z', that's about
  39.   to be checked. if not in this range, the Function will return False.
  40.  
  41.   Returns: Function returns True if the given drive is valid, else
  42.   False (!). bLocal is set if drive is local, bSUBST if drive is
  43.   substituted. if Function returns False, the Booleans are undefined.
  44. }
  45. Var
  46.   rCPU: Dos.Registers;
  47. begin
  48.   { --- Call Dos and process returns --- }
  49.   if not (UpCase(cDrive) in ['A'..'Z']) then { --- letter OK?--- }
  50.     IsDriveValid := False
  51.   else
  52.   begin
  53.     { --- Valid letter, set up For the Dos-call --- }
  54.     rCPU.bx := ord(UpCase(cDrive))-ord('A')+1;
  55.     rCPU.ax := $4409;
  56.     { --- Call the Dos IOCTL (InOutConTroL)-Functions --- }
  57.     Intr($21, rCPU);
  58.     if (rCPU.ax and FCarry) = FCarry then
  59.       IsDriveValid := False
  60.     else
  61.     begin { --- drive is valid, check status --- }
  62.       IsDriveValid := True;
  63.       bLocal := ((rCPU.dx and $1000) = $0000);
  64.       if bLocal then
  65.         bSUBST := ((rCPU.dx and $8000) = $8000)
  66.       else
  67.         bSUBST := False;
  68.     end;
  69.   end;
  70. end;
  71.  
  72. Var
  73.   cCurChar : Char;          { loop counter, drive }
  74.   bLocal,
  75.   bSUBST   : Boolean;       { drive local/remote?; SUBSTed or not? }
  76.  
  77. begin
  78.   { --- Write header --- }
  79.   Writeln; Writeln('  VALID DRIVES:'); Writeln;
  80.   { --- Loop from 'A' to 'Z', For each iteration check a drive --- }
  81.   For cCurChar := 'A' to 'Z' do
  82.     if IsDriveValid(cCurChar, bLocal, bSUBST) then
  83.     begin
  84.       Write(cCurChar, ': ');
  85.       if bLocal then
  86.         Write(' local ')
  87.       else
  88.         Write(' remote');
  89.       if bSUBST then
  90.         Write('   SUBSTed ')
  91.       else
  92.         Write('   not SUBSTed');
  93.       Writeln;
  94.     end;
  95.   { --- Write footer --- }
  96.   Writeln;
  97. end.
  98.  
  99. {
  100. The code is simple. It calls the Dos IOCTL-service #09h, 'Is Drive Remote',
  101. with the drive number (1-A:, 2-B:, ...) in the bl-register. if the drive isn't
  102. valid, the carry flag is set. if valid, carry is clear, and the dx-register
  103. contains bit-fields you're interested in. Bit 12 is 1 if remote, 0 if local. if
  104. local, bit 15 is 1 if the drive is a substitution. In TP, you get access to
  105. them, in this Case, by using the 'and'-binary operator.
  106.  
  107. I guess you're interested in making a Filemanager or a report util or that
  108. like. then, you're maybe interested to get source For detection of CD-ROM
  109. drives and floppys? if so, post me a new msg. I always like to recieve new
  110. mail... I didn't include this here, this msg is too long without that extra
  111. code. Feel free to Write if you get any problems.
  112. }